package org.holynite.fieldmanage.services

import org.holynite.fieldmanage.Utils.ManagementException
import org.holynite.fieldmanage.ejbs.CustomerTypeManagement
import org.holynite.fieldmanage.entities.CustomerType
import org.holynite.fieldmanage.persistence.CustomerTypeEAO
import org.holynite.fieldmanage.types.Exceptions

import javax.ejb.EJB
import javax.ejb.Stateless

/**
 * Created by midnite on 15/1/20.
 */
@Stateless(name = "customerTypeControl", mappedName = "customerTypeControl")
class CustomerTypeControlBean implements CustomerTypeManagement {

	@EJB(beanName = "customerTypeEao")
	CustomerTypeEAO ctEao

	@Override
	void addType(CustomerType newType) throws ManagementException {
		try {
			ctEao.save(newType)
		} catch (Exception e) {
			throw new ManagementException(Exceptions.CustomerType)
		}
	}

	@Override
	void saveType(CustomerType type) throws ManagementException {
		try {
			ctEao.update(type)
		} catch (Exception e) {
			throw new ManagementException(Exceptions.CustomerType)
		}
	}

	@Override
	void removeType(String id) throws ManagementException {
		try {
			ctEao.delete(CustomerType, id)
		} catch (Exception e) {
			throw new ManagementException(Exceptions.CustomerType)
		}
	}

	@Override
	List<CustomerType> searchTypes(String keyword) {
		ctEao.searchCustomerType(keyword)
	}

	@Override
	Boolean checkTypeInUsing(CustomerType type) {
		false
	}
}
